import java.sql.*;

/**
 * @auther wsy
 * @auther MI
 * @create TestJdbc.PACKAGE_NAME
 * @create 13:28
 * @create 2021/7/5 星期一
 */
public class MyJdbc {

    public static void main(String[] args) throws ClassNotFoundException, SQLException {

        /*1.反射加载驱动*/
        Class.forName("com.mysql.jdbc.Driver");
        /*2.创建连接对象*/
        Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/" +
                "user?useUnicode=true&characterEncoding=utf-8&serverTimeZone=utc","root","root");
        /*3.sql语句*/
        /*String sql="select * from user";*/
        /*String sql1="delete from user where id=?";*/
        /*String sql2="insert into user_a(id,name,age,height,weight)values (7,'高鹏',27,178,120)";*/
        String sql3="update user_a set weight=130 where id=?";
        /*4.执行sql语句*/
        /*PreparedStatement preparedStatement = connection.prepareStatement(sql);*/
       /*PreparedStatement preparedStatement = connection.prepareStatement(sql1);*/
        PreparedStatement preparedStatement = connection.prepareStatement(sql3);
        /*5获取执行结果*/
        /*preparedStatement.setObject(1,"6");*/
        /*ResultSet resultSet = preparedStatement.executeQuery();*/
        preparedStatement.setObject(1,"7");
        int i =preparedStatement.executeUpdate();
        /*6获取返回值*/
        if(i>0){
            System.out.println("yes");
        }else{
            System.out.println("no");
            connection.rollback();
        }
      /* while(resultSet.next()){
            int id = resultSet.getInt(1);
            String name = resultSet.getString(2);
            int score = resultSet.getInt(3);
            String gender = resultSet.getString(4);
            System.out.println(id+"---"+name+"---"+score+"---"+gender);
        }*/
        /*7关闭连接*/
        /*resultSet.close();*/
        preparedStatement.close();
        connection.close();
    }

}
